<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='./vue.global.js'></script>
</head>

<body>
    <div id='app'></div>
    <script>
        const app = Vue.createApp({
            myOption: 'hello from dad!',
            data() {
                return {
                    count: 0
                }
            },
            template: `
            <son v-if="count < 5" :count="count"></son>
            {{count}}
            <button @click="count++">add</button>
            `,

            // 组件被创建
            created() {
                console.log("dad created");
            },

        })

        // 为自定义的选项 'myOption' 注入一个处理器。
        // 共享的逻辑为：组件创建实例时 如果组件有myOption选项存在 则打印之
        app.mixin({
            created() {
                const myOption = this.$options.myOption
                if (myOption) {
                    console.log(myOption)
                }
            }
        })

        // 将myOption也添加到子组件
        app.component('son', {
            myOption: 'hello from son!',
            props:["count"],
            template:`<div>son:{{count}}</div>`,

            // 组件被创建
            created() {
                console.log("son created");
            },
        })

        const vm = app.mount('#app')
    </script>
</body>

</html>